<?php
	/**
	 * IndexController
	 * @author David Ivins
	 */
	class IndexController extends CustomControllerAction
	{
		/**
		 * indexAction
		 */
		public function indexAction() {
		
			# Get the five most recent photos uploaded to the site
			$media_obj = new MediaSDBManager();
			$media_obj_result = $media_obj->query("['date' > '0'] sort 'date' desc", '5');

			# Loop through the new media
			foreach($media_obj_result as $this_media) {
				$media = $this_media->getAttributes();
				
				# Get thumbnail
				$desired_thumb_width = "160";
				$thumb_mgr = new ThumbnailManager($this->_sdb, $this->_s3, $this->_config, $this->_logger);
				$media['thumb_url'] = $thumb_mgr->getThumbnail($this_media->getId(), $desired_thumb_width);
				
				# Get uploaders username
				$user = new User();
				$user->load($media[user_id]);

				$media['username'] = $user->getAttribute('username');

				# Get number of comments on this photo
				$comment_obj = new CommentSDBManager();
				$comments = $comment_obj->getByFieldValue('photo_id', $this_media->getId());
				$media['comment_number'] = count($comments);

				$new_media[] = $media;
			}

			# Send this media to the smarty template
			$this->view->new_media = $new_media;
		}
	}
